﻿CREATE VIEW [dbo].[ASMS_V_CapitalDecreaseBill]
	AS 
SELECT CDB.*,
	MDIIT.Name as InvoiceTypeName,
case CDB.PayeeRoleType
	when 1 then (select C.[Name] from ASMS_Customer as C where C.Id = CDB.PayeeRole)
    when 2 then (select S.[Name] from ASMS_Supplier as S where S.Id = CDB.PayeeRole)
    when 3 then (select STAFF.[Name] from ASMS_Staff as STAFF where STAFF.Id = CDB.PayeeRole)
	else CDB.PayeeRole 
	end as PayeeRoleName
FROM ASMS_CapitalDecreaseBill as CDB
	left join ASMS_MasterDataItem as MDIIT on MDIIT.Code = CDB.InvoiceType
